#include "mq_connection.hpp"

int main()
{
    // 1.实例化异步工作对象
    mymq::Async::ptr async_worker = std::make_shared<mymq::Async>();
    // 2.实例化连接对象
    mymq::Connection::ptr conn = std::make_shared<mymq::Connection>("127.0.0.1", 8085, async_worker);
    // 3.通过连接，实例化信道
    mymq::Channel::ptr channel = conn->openChannel();
    // 4.通过信道提供的服务，完成需求
    //  1.声明交换机，类型为广播
    google::protobuf::Map<std::string, std::string> emp_args;
    channel->declareExchange("exchange1", mymq::ExchangeType::TOPIC, true, false, emp_args);
    //  2.声明队列 queue1
    channel->declareQueue("queue1", true, false, false, emp_args);
    //  3.声明队列 queue2
    channel->declareQueue("queue2", true, false, false, emp_args);
    //  4.绑定队列1，bingingkey 设置为 queue1
    channel->queueBind("exchange1", "queue1", "queue1");
    //  5.绑定队列2，bingingkey 设置为 news.music.#
    channel->queueBind("exchange1", "queue2", "news.music.#");

    // 5.循环向交换机发布消息
    for (int i = 0; i < 10; i++)
    {
        mymq::BasicProperties bp;
        bp.set_id(mymq::UUIDHelper::uuid());
        bp.set_delivery_mode(mymq::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->basicPublish("exchange1", &bp, "hello world-" + std::to_string(i));
    }

    // 主题交换
    mymq::BasicProperties bp;
    bp.set_id(mymq::UUIDHelper::uuid());
    bp.set_delivery_mode(mymq::DeliveryMode::DURABLE);
    bp.set_routing_key("news.music.sport");
    channel->basicPublish("exchange1", &bp, "hello news.music.sport");
    // 不匹配，收不到
    bp.set_routing_key("news.sport");
    channel->basicPublish("exchange1", &bp, "hello news.sport");
    // 6.关闭信道
    conn->closeChannel(channel);
    return 0;
}